scikit-learn: GridSearchCV
https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.GridSearchCV.html
概要 - 3.2. Tuning the hyper-parameters of an estimatorにおけるsearchの構成要素との対応
推論器:イニシャライザのestimator引数
パラメタ空間:イニシャライザのparam_grid引数
辞書でパラメタ空間を表す
リストに複数のパラメタ空間を詰めて渡せる
https://scikit-learn.org/stable/modules/grid_search.html#exhaustive-grid-search にてリストを渡す例
code:params_grid_example.py
param_grid = [
{'C': 1, 10, 100, 1000, 'kernel': 'linear'},
{'C': 1, 10, 100, 1000, 'gamma': 0.001, 0.0001, 'kernel': 'rbf'},
]
one with a linear kernel and C values in [1, 10, 100, 1000], and the second one with an RBF kernel, and the cross-product of C values ranging in [1, 10, 100, 1000] and gamma values in [0.001, 0.0001].
「linearカーネルでCの値を[1, 10, 100, 1000]で検索、もう1つRBFカーネルで、Cの値は[1, 10, 100, 1000]からgammaの値は[0.001, 0.0001]から交差積をとって検索」
候補を検索またはサンプリングする方法:徹底的に検索
交差検証スキーム:イニシャライザのcv引数
For integer/None inputs, if the estimator is a classifier and y is either binary or multiclass, StratifiedKFold is used. In all other cases, KFold is used.
3.1.2. Cross validation iteratorsが適用できる
スコア関数:イニシャライザのscoring引数
3.2.4.1 (3.2.4. Tips for parameter search)
引数
error_score
default=np.nan
頑健になっている(落ちるfoldがあっても大丈夫)
ref: 3.2.4.6(3.2.4. Tips for parameter search)
refit
default=True
デフォルトでは見つかったパラメタ・全データセットで再訓練される!
Refit an estimator using the best found parameters on the whole dataset.
TODO 必要に応じて詳細に見る
verbose
4以上で一番詳しい出力となる
https://scikit-learn.org/stable/modules/grid_search.html#exhaustive-grid-search
Examples
(積ん読)Sample pipeline for text feature extraction and evaluation